Skip to content

Conversation

@resistor
Copy link
Collaborator

This is an implentation of RISCV vendor-specific relocation support in LLD, derived from a working prototype implementation in the downstream CHERIoT repository: CHERIoT-Platform/llvm-project@3d6d6f7
At this time I am seeking design feedback on the shape of the implementation, while I work on developing tests that do not depend on CHERIoT.

Key elements of the design include:

  • Representing vendor-namespaced relocs by treating RelType as a bitfield
  • Creating a reloc iterator that can fold R_RISCV_VENDOR relocs into to the bitfield on the following reloc.

@resistor
Copy link
Collaborator Author

@lenary for feedback

@github-actions
Copy link

github-actions bot commented Nov 18, 2025

🐧 Linux x64 Test Results

  • 3718 tests passed
  • 57 tests skipped

Copy link
Member

@lenary lenary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the iterator, it seems clean and a sensible wrapper for the logic.

I have more feedback about the bitfields, at the moment, but overall I'm happy with the direction so far.

I haven't yet had to think about dynamic relocations, and if they have some differences compared to the existing design/spec (are local symbols a problem here?)

auto riscvVendorString = getRISCVVendorString(reloc.type);
if (ctx.arg.emachine == llvm::ELF::EM_RISCV && riscvVendorString) {
Symbol &vendorSym = *ctx.symtab->addSymbol(Defined{
ctx, ctx.internalFile, *riscvVendorString, llvm::ELF::STB_GLOBAL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx, ctx.internalFile, *riscvVendorString, llvm::ELF::STB_GLOBAL,
ctx, ctx.internalFile, *riscvVendorString, llvm::ELF::STB_LOCAL,

I think we've said these need to be local, but maybe that's not right for dynamic relocs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I recalled that dynamic relocations could only point to global symbols, but I'm failing to find that requirement in the ELF spec.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oracle docs seem to agree with you:

The .dynsym table begins with the standard NULL symbol, followed by the files global symbols. STT_FILE symbols are typically not present in this symbol table. STT_SECTION symbols might be present if required by relocation entries.

From: https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-79797.html#stlac

I will go back to the ABI about this. We made them local to echo mapping symbols, but evidently that doesn't work for vendor-specific dynamic relocations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Can you share the ABI discussion link once you bring it there?

Copy link
Member

@lenary lenary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems clear to me what's going on (though I've implemented this once already). I would be happy to help review/maintain this code if it was landed.

One Nit below.

Do we want to make sure we never parse a relocation from a file that's more than 255? They would have had to have been made deliberately, but are possible to encode on rv64. It's the sort of error that's useful to have and remove in the future, if the abi ever gets so many relocations.

@github-actions
Copy link

github-actions bot commented Nov 20, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants